package pers.cz.chat.filter;

import pers.cz.chat.constants.Commands;
import pers.cz.netty.filter.FilterHandler;
import pers.cz.netty.filter.FilterHandlerContext;
import pers.cz.netty.protocal.Message;
import pers.cz.netty.protocal.MsgType;

/**
 * @version 1.0
 * @description: 展示在线用户拦截器
 * @author: ChengZhi 0336
 * @create: 2025-01-06 18:14
 **/
public class ShowUsersFilter implements FilterHandler<Message, Object> {

	@Override
	public boolean approve(Message message, Object obj, FilterHandlerContext<Message, Object> handlerContext) {
		Object contentOriginal = message.getContent();
		if (contentOriginal instanceof String) {
			String content = (String) contentOriginal;
			if (content.trim().startsWith(Commands.SHOW.getCommand())) {
				message.setMsgType(MsgType.SHOW);
			}
		}

		return handlerContext.doFilter(message, obj);
	}
}
